package com.gd.iot.energy.util;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * 集合工具
 */
public class CustomCollUtil {

    /**
     * 数组转list long
     * @param arr
     * @return
     */
    public static List<Long> convertToLongList(long[] arr){
        List<Long> res = new ArrayList<>(arr.length);
        for (long l : arr) {
            res.add(l);
        }
        return res;
    }

    public static List<Integer> strListToIntegerList(List<String> stringList) {
        List<Integer> list = new ArrayList<>();
        if (stringList != null && !stringList.isEmpty()) {
            for (String str : stringList) {
                list.add(Integer.valueOf(str));
            }
        }
        return list;
    }

    public static List<String> intListToStringList(List<Integer> intList) {
        List<String> list = new ArrayList<>();
        if (intList != null && !intList.isEmpty()) {
            for (Integer str : intList) {
                list.add(String.valueOf(str));
            }
        }
        return list;
    }

    /**
     * 合并list，用逗号隔开
     * @param intList
     * @param split
     * @return
     */
    public static String joinIntListToString(List<Integer> intList,Character split) {
        StringBuilder res = new StringBuilder();
        if (intList != null && !intList.isEmpty()) {
            for (Integer str : intList) {
                res.append(String.valueOf(str)).append(split);
            }
        }
        return intList==null || intList.isEmpty() ? "" : res.toString().substring(0, res.toString().length() - 1);
    }
}
